#!/bin/bash

# This script creates route files directly on the server
# Copy and paste the commands below into your server terminal

echo "# Run these commands on the production server (47.237.10.129):"
echo "# ssh root@47.237.10.129"
echo
echo "cd /opt/cumrbull/backend/src/routes/"
echo

# Create auth.js
echo "cat > auth.js << 'EOF'"
cat temp-routes/auth.js
echo "EOF"
echo

# Create users.js
echo "cat > users.js << 'EOF'"
cat temp-routes/users.js
echo "EOF"
echo

# Create menu.js
echo "cat > menu.js << 'EOF'"
cat temp-routes/menu.js
echo "EOF"
echo

# Create orders.js
echo "cat > orders.js << 'EOF'"
cat temp-routes/orders.js
echo "EOF"
echo

# Create coupons.js
echo "cat > coupons.js << 'EOF'"
cat temp-routes/coupons.js
echo "EOF"
echo

# Create payments.js
echo "cat > payments.js << 'EOF'"
cat temp-routes/payments.js
echo "EOF"
echo

# Create admin.js
echo "cat > admin.js << 'EOF'"
cat temp-routes/admin.js
echo "EOF"
echo

echo "# Verify files created:"
echo "ls -la /opt/cumrbull/backend/src/routes/"
echo "wc -l /opt/cumrbull/backend/src/routes/*.js"
echo
echo "# Restart backend service:"
echo "cd /opt/cumrbull/backend"
echo "pkill -f 'node src/app.js'"
echo "nohup node src/app.js > backend.log 2>&1 &"
echo "sleep 3"
echo "ps aux | grep 'node src/app.js' | grep -v grep"
echo "netstat -tlnp | grep :3000"
echo "tail -10 backend.log"